package com.qf.day13.homework;

import java.util.Map;
import java.util.TreeMap;
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;

public class WorldCupChampions {
    public static void main(String[] args) {
        Map<Integer, String> champions = new TreeMap<>();
        //添加冠军成员
        champions.put(2006, "意大利");
        champions.put(2002, "巴西");
        champions.put(1998, "法国");
        champions.put(1994, "巴西");
        champions.put(1990, "德国");
        champions.put(1986, "阿根廷");
        champions.put(1982, "意大利");
        champions.put(1978, "阿根廷");
        champions.put(1974, "德国");
        champions.put(1970, "巴西");
        champions.put(1966, "英格兰.");
        champions.put(1962, "巴西");
        champions.put(1958, "巴西");
        champions.put(1954, "德国");
        champions.put(1950, "乌拉圭");
        champions.put(1938, "意大利");
        champions.put(1934, "意大利");
        champions.put(1930, "乌拉圭");
       
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入一个年份：");
        int year = scanner.nextInt();

        String champion = champions.get(year);
        if (champion != null) {
            System.out.println(year + "年的世界杯冠军是：" + champion);
        } else {
            System.out.println(year + "年没有举办世界杯");
        }

        System.out.println("请输入一支球队的名字：");
        String teamName = scanner.next();

        List<Integer> titles = new ArrayList<>();
        for (Map.Entry<Integer, String> entry : champions.entrySet()) {
            if (entry.getValue().equals(teamName)) {
                titles.add(entry.getKey());
            }
        }

        if (titles.isEmpty()) {
            System.out.println(teamName + "没有获得过世界杯");
        } else {
            System.out.print(teamName + "夺冠的年份列表：");
            for (int i = 0; i < titles.size(); i++) {
                System.out.print(titles.get(i));
                if (i < titles.size() - 1) {
                    System.out.print("、");
                }
            }
        }
        scanner.close();
    }
}
